-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPENNLP-1607: SimpleClassPathModelFinder not returning list of matching paths #652
OPENNLP-1607: SimpleClassPathModelFinder not returning list of matching paths #652
Conversation
Updated SimpleClassPathModelFinder to return a list of paths instead of the delimiter
@codyfearer Thx for the PR. A screenshot is not a proof of correctness for the intended behavior. Could you therefore add a test case that demonstrates the difference in outcomes with your code change? |
There is already a unit test but the branch isn't hit because of the surefire configuration. @codyfearer Maybe just add an additional execution phase for surefire without the Something like <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin}</version>
<configuration>
<forkCount>${opennlp.forkCount}</forkCount>
<useSystemClassLoader>false</useSystemClassLoader>
<failIfNoSpecifiedTests>false</failIfNoSpecifiedTests>
</configuration>
<executions>
<execution>
<id>ucp</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<argLine>-Xmx2048m -Dorg.slf4j.simpleLogger.defaultLogLevel=off --add-opens java.base/jdk.internal.loader=ALL-UNNAMED</argLine>
</configuration>
</execution>
<!-- This phase is here to trigger a fallback to the classpath from the system properties, which cannot be hit, if --add-opens is present. -->
<execution>
<id>no-reflection</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<argLine>-Xmx2048m -Dorg.slf4j.simpleLogger.defaultLogLevel=off</argLine>
</configuration>
</execution>
</executions>
</plugin> There might be better names for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check CI results? Looks like this change is broken on Windows? :)
I guess, that the additional surefire phase now reveals another bug (with Windows). I think, that it needs an adjustment of the path similar to the adjustment done in private List<URI> getURIsFromJar(URL fileUrl, boolean isWindows) throws IOException
@codyfearer I think Index: opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java b/opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
--- a/opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java (revision 8d3b2dacc1da8d301734e9004b998b001f6619b0)
+++ b/opennlp-tools-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java (date 1726648019585)
@@ -63,8 +63,8 @@
private static final Logger logger = LoggerFactory.getLogger(SimpleClassPathModelFinder.class);
private static final String FILE_PREFIX = "file";
- private static final Pattern CLASSPATH_SEPARATOR_PATTERN = Pattern.compile("[;:]");
- // ; for Windows, : for Linux/OSX
+ private static final Pattern CLASSPATH_SEPARATOR_PATTERN_WINDOWS = Pattern.compile(";");
+ private static final Pattern CLASSPATH_SEPARATOR_PATTERN_UNIX = Pattern.compile(":");
/**
* By default, it scans for "opennlp-models-*.jar".
@@ -190,20 +190,26 @@
if (fromUcp != null && fromUcp.length > 0) {
return Arrays.asList(fromUcp);
} else {
- final String cp = System.getProperty("java.class.path", "");
- final String[] matches = CLASSPATH_SEPARATOR_PATTERN.split(cp);
- final List<URL> jarUrls = new ArrayList<>();
- for (String classPath: matches) {
- try {
- jarUrls.add(new URL(FILE_PREFIX, "", classPath));
- } catch (MalformedURLException ignored) {
- //if we cannot parse a URL from the system property, just ignore it...
- //we couldn't load it anyway
- }
- }
- return jarUrls;
- }
- }
+ return getClassPathUrlsFromSystemProperty();
+ }
+ }
+ }
+
+ private List<URL> getClassPathUrlsFromSystemProperty() {
+ final String cp = System.getProperty("java.class.path", "");
+ final String[] matches = isWindows()
+ ? CLASSPATH_SEPARATOR_PATTERN_WINDOWS.split(cp)
+ : CLASSPATH_SEPARATOR_PATTERN_UNIX.split(cp);
+ final List<URL> jarUrls = new ArrayList<>();
+ for (String classPath: matches) {
+ try {
+ jarUrls.add(new URL(FILE_PREFIX, "", classPath));
+ } catch (MalformedURLException ignored) {
+ //if we cannot parse a URL from the system property, just ignore it...
+ //we couldn't load it anyway
+ }
+ }
+ return jarUrls;
}
/*
should do the trick on Windows. The issue with the combined regex is, that Windows cp elements start with "C:" for example and a split with "[;:]" will be broken in that case. |
Updating getClassPathUrlsFromSystemProperty to handle Windows paths
Added the code for Windows paths. Was able to successfully build on a Windows 11 VM |
Updated SimpleClassPathModelFinder to return a list of paths instead of the delimiter
Thank you for contributing to Apache OpenNLP.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
Does your PR title start with OPENNLP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
Has your PR been rebased against the latest commit within the target branch (typically main)?
Is your initial contribution a single, squashed commit?
For code changes:
For documentation related changes:
Note:
Please ensure that once the PR is submitted, you check GitHub Actions for build issues and submit an update to your PR as soon as possible.